package top.ed333.mcplugins.configurableevents.action;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

public final class Actions implements Iterable<Action> {
    private final List<Action> actions;

    public Actions(List<Action> actions) {
        this.actions = actions;
    }

    @Contract(value = " -> new", pure = true)
    @Override
    public @NotNull Iterator<Action> iterator() {
        return new ActionsIterator(actions);
    }

    private static final class ActionsIterator implements Iterator<Action> {
        private final List<Action> data;
        private int index = 0;

        private ActionsIterator(List<Action> data) {
            this.data = data;
        }

        @Override
        public boolean hasNext() {
            return index < data.size();
        }

        @Override
        public Action next() {
            if (hasNext()) {
                return data.get(index++);
            } else {
                throw new java.util.NoSuchElementException();
            }
        }
    }
}
